def convert_mttf_or_fit(mttf_or_fit):
    billion = 1000000000
    result = billion / mttf_or_fit
    return result


def calculate_failure_rate(systems):
    failure_rates = []
    for system in systems:
        fit = (
            system.get("fit")
            if system.get("fit")
            else convert_mttf_or_fit(system.get("mttf"))
        )
        failure_rate = fit * system.get("count")
        failure_rates.append(failure_rate)

    system_failure_rate = 0
    for item in failure_rates:
        system_failure_rate += item

    return system_failure_rate


def calculate_mttf(systems):
    fit = calculate_failure_rate(systems)
    mttf = convert_mttf_or_fit(mttf_or_fit=fit)
    return mttf


def calculate_mttf_for_redundancy(mttf, mttr):
    result = (mttf * mttf) / (2 * mttr)
    return result, ""


def calculate_mttf_for_subsystem(number_of_items, mttf, fail_threshold):
    mu = number_of_items / mttf
    subsystem_mttf = fail_threshold * (1 / mu)
    return subsystem_mttf


def calculate_time_until_fail(failure_rate, fail_threshold):
    time_until_fail = fail_threshold / failure_rate
    return time_until_fail


def calculate_annual_failure_rate(number_of_items, time_period, mttf):
    annual_failure_rate = (number_of_items * time_period) / mttf
    return annual_failure_rate
